package com.bookshop.entity.response;

import java.util.HashMap;

/**
 * @author g2l
 * @create 2022-07-28 21:33
 */
public class R extends HashMap<String, Object>{

    // 数据直接使用put存入即可
    public R put(String key, Object value){
        super.put(key, value);
        return this;
    }

    // 专门封装的message信息
    public R message(String  message){
        this.put("message", message);
        return this;
    }

    public static R ok(){
        R r = new R();
        r.put("code", 200);
        r.put("status", ResponseStatus.SUCCESS);
        return r;
    }

    public static R error(){
        R r = new R();
        r.put("code", 500);
        r.put("status", ResponseStatus.FAIL);
        return r;
    }

    // 专门封装的status信息，一般不修改，项目重构后可修改
    public R status(ResponseStatus  status){
        this.put("status", status);
        return this;
    }
}
